package users

import (
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetMessageListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetMessageListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMessageListLogic {
	return &GetMessageListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetMessageListLogic) GetMessageList(req *types.GetMessageListRequest) (resp *types.Response, err error) {
	list, err := l.svcCtx.UserRpc.GetMessageList(l.ctx, &userclient.GetMessageListReq{
		UserId:   req.User_id,
		Page:     req.Page,
		PageSize: req.Page_size,
	})
	if err != nil {
		return nil, err
	}
	return &types.Response{
		Code:    200,
		Message: "获取成功",
		Data:    list.Messages,
	}, nil
}
